#!/usr/bin/perl
use strict;
use warnings;
use autodie;

use Getopt::Std;

my %opts;

getopts('mg', \%opts);

# if ( defined $opts{f}) {
	# my @high=("PASS");
# }

open in, $ARGV[0];
open OUT1, ">$ARGV[1]";
open OUT2, ">$ARGV[2]";
open OUT3, ">$ARGV[3]";

my @high;

while(<in>) {
	if(! /^#/) {
	
		my @vcf = split '\t', $_;
		
		if ($opts{m}) {
			@high=("PASS", "Allele_frequency_less_than_20\%\;Allele_frequency_less_than_10\%", "Allele_frequency_less_than_10\%\;Allele_frequency_less_than_20\%", "INDEL_Allele_frequency_less_than_10\%\;INDEL_Allele_frequency_less_than_25\%", "INDEL_Allele_frequency_less_than_25\%\;INDEL_Allele_frequency_less_than_10\%");
			
			if($vcf[6] =~ /^$high[0]$/ or $vcf[6] =~ /^$high[1]$/ or $vcf[6] =~ /^$high[2]$/ or $vcf[6] =~ /^$high[3]$/ or $vcf[6] =~ /^$high[4]$/) {
				print OUT1 $_;
			}else{
				print OUT2 $_;
			}
			
		
		}elsif ($opts{g}) {
			@high=("PASS", "Allele_frequency_less_than_20\%", "INDEL_Allele_frequency_less_than_25\%");
			
			if($vcf[6] =~ /^$high[0]$/ or $vcf[6] =~ /^$high[1]$/ or $vcf[6] =~ /^$high[2]$/) {
				print OUT1 $_;
			}else{
				print OUT2 $_;
			}
		
		}else {
			@high=("PASS");
			
			if($vcf[6] =~ /^$high[0]$/) {
				print OUT1 $_;
			}else{
				print OUT2 $_;
			}
		
		}

		
	}else{
		print OUT3 $_;
	}
}

